home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / OSK / VARARGS.H < prev   
C/C++ Source or Header  |  1988-08-23  |  2KB  |  55 lines

  1. /* varargs.h for os9/68k by Robert A. Larson    */
  2. /* version 0 for os9/68k C 2.0 04/20/86        */
  3. /* varargs is a "portable" way to write a routine that takes a variable */
  4. /* number of arguements.  This implemination agrees with both the 4.2bsd*/
  5. /* and Sys V documentation of varargs.  Note that just because varargs.h*/
  6. /* is used does not mean that it is used properly.            */
  7. /* Ignore the "expression with little effect" warnings.  (Seems to be a */
  8. /* compiler bug.)                            */
  9.  
  10. #define va_alist    _va_arg1, _va_arg2, _va_arg3
  11.  
  12. #define va_dcl        unsigned _va_arg1, _va_arg2, _va_arg3;
  13.  
  14. typedef    struct {
  15.       unsigned _va_at;  /* number of arguments used, 0, 1, or more  */
  16.                             /* (double as first arg counts as 2)        */
  17.       union {
  18.         struct {
  19.           unsigned _va_uns1, _va_uns2;
  20.         } _va_uuns;
  21.         double _va_udouble;
  22.       } _va_union;
  23.       char *_va_pointer;
  24.         } va_list;
  25.  
  26. #define    va_start(pvar)    ( (pvar)._va_at = 0,                \
  27.               (pvar)._va_union._va_uuns._va_uns1 = _va_arg1,\
  28.               (pvar)._va_union._va_uuns._va_uns2 = _va_arg2,\
  29.               (pvar)._va_pointer = (char *) &_va_arg3    \
  30.             )
  31.  
  32. #define va_arg(pvar, type)    (                \
  33.     ((pvar)._va_at++) ? (                    \
  34.         ((pvar)._va_at == 2) ? (            \
  35.             (sizeof(type) == 8) ? (            \
  36.                 *(((type *)((pvar)._va_pointer))++)    \
  37.             ) : (type)(                \
  38.                 (pvar)._va_union._va_uuns._va_uns2    \
  39.             )                    \
  40.         ) : (                        \
  41.  
  42.             *(((type *)((pvar)._va_pointer))++)    \
  43.         )                        \
  44.     ) : (                            \
  45.         (sizeof(type) == 8) ? (type)(            \
  46.             (pvar)._va_at++,            \
  47.             (pvar)._va_union._va_udouble        \
  48.         ) : (type)(                    \
  49.             (pvar)._va_union._va_uuns._va_uns1    \
  50.         )                        \
  51.     )                            \
  52. )
  53.  
  54. #define va_end(pvar)                /* va_end is simple */
  55.